﻿using DtoFw;
using DtoFw.Interface;
using DtoFw.Query;
using DtoFw.Result;
using System;
using System.Linq;

namespace SceneEvidenceAPISDK
{
    public class ApiUser : Base, IUser
    {
        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public BaseGenericResult<MainUserLoginInfo> Login(MainUserLoginQuery query)
        {
            var login = HttpTools.Post<BaseGenericResult<MainUserLoginInfo>>(query,
                base.GetApiRouter("Login"));
            if (login.Success)
            {
                HttpTools.accessToken = login.Data.Token;
                HttpTools.refreshToken = login.Data.RefreshToken;
            }
            return login;
        }
        /// <summary>
        /// 获取登录用户对象
        /// </summary>
        /// <returns></returns>
        public BaseGenericResult<MainUserLoginResult> GetLoginUserInfo()
        {
            return HttpTools.Get<BaseGenericResult<MainUserLoginResult>>(
                 base.GetApiRouter("GetLoginUserInfo"));
        }
        /// <summary>
        /// 获取指定用户
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaseGenericResult<UserInfoEditInfo> GetUserInfo(long id)
        {
            return HttpTools.Get<BaseGenericResult<UserInfoEditInfo>>(
                 base.GetApiRouter("GetUserInfo", id.ToString()));
        }
        /// <summary>
        /// 获取分页用户列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public BaseGenericResult<Pager<UserinfoResult>> QueryUserList(UserInfoQuery query)
        {
            return HttpTools.Get<BaseGenericResult<Pager<UserinfoResult>>>(query,
                 base.GetApiRouter("QueryUserList"));
        }
        /// <summary>
        /// Token刷新
        /// </summary>
        /// <param name="refreshtoken"></param>
        /// <returns></returns>
        public BaseGenericResult<string> RefreshToken(string refreshtoken)
        {
            var result = HttpTools.Get<BaseGenericResult<string>>(
                 base.GetApiRouter("RefreshToken", refreshtoken));
            if (result.Success)
                HttpTools.accessToken = result.Data;
            return result;
        }
        /// <summary>
        /// 密码重置
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public BaseResult RestPassWord(RestPwdQuery query)
        {
            return HttpTools.Put<BaseResult>(query,
                 base.GetApiRouter("RestPassWord"));
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public BaseResult PutPassWord(PutPwdQuery query)
        {
            return HttpTools.Put<BaseResult>(query, base.GetApiRouter("PutPassWord"));
        }
        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public BaseResult Post(UserInfoAddInfo info)
        {
            return HttpTools.Post<BaseResult>(info,
                base.GetApiRouter("Post"));
        }
        /// <summary>
        /// 编辑用户
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public BaseResult Put(UserInfoEditInfo info)
        {
            return HttpTools.Put<BaseResult>(info,
                 base.GetApiRouter("Put"));
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public BaseResult Delete(DeleteDto query)
        {
            return HttpTools.Delete<BaseResult>(query,
                base.GetApiRouter("DelUsers"));
        }
    }
}
